package sample.enums;

import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public enum  MapType {
    baidu("baidu", "百度", 1),
    gaode("gaode", "高德", 2),
    m360("360", "360", 4),
    tencent("tencent", "腾讯", 3),
    sogou("sogou", "搜狗", 5);

    private String code;
    private String desc;
    private Integer sort;

    public static final Map<String, String> map = Stream.of(values()).collect(Collectors.toMap(MapType::getCode, MapType::getDesc));

    public static final List<MapType> list = Stream.of(values()).sorted(Comparator.comparing(MapType::getSort)).collect(Collectors.toList());

    MapType(String code, String desc, Integer sort){
        this.code = code;
        this.desc = desc;
        this.sort = sort;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public Integer getSort() {
        return sort;
    }

    @Override
    public String toString() {
        return "MapType{" +
                "code='" + code + '\'' +
                ", desc='" + desc + '\'' +
                ", sort=" + sort +
                '}';
    }

    public static void main(String[] args) {
        System.out.println(MapType.list);
    }
}
